package com.fivec.javaproject.service;

import com.alibaba.fastjson.JSONObject;
import com.fivec.javaproject.Constants;
import com.fivec.javaproject.bean.HeadlineCommon;

import com.fivec.javaproject.bean.HeadlineData;
import com.fivec.javaproject.net.HttpUtils;

import java.util.List;

/**
 * @author wangyizhu
 * @version "1.8.0_131"
 * @email 2641956765@qq.com
 * @desc:
 * @Time 2021/12/18 10:42
 */
public class HeadlineService {
    /**
     * 该方法用于获取新闻头条数据
     *
     * @param type
     * @return Weather
     */

    public List<HeadlineData> getHeadlineMessage(String type) {
        String url = Constants.HEADLINE_URL
                + "?type=" + type
                + "&key=" + Constants.HEADLINE_KEY
                + "&page_size=3";
        String result = HttpUtils.get(url);
        // System.out.println(result);
        //json解析
        HeadlineCommon headlineCommon = JSONObject.parseObject(result, HeadlineCommon.class);
        return headlineCommon.result.getData();
    }
}
